﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RL = Bettzueche.RLLibrary.Types;

namespace RLProjectUnitTest
{
    [TestClass]
    public class DimensionTest
    {
        [TestMethod]
        public void CheckDimension_0Partitionen() {
            RL.Tiling dim = new RL.Tiling(0.0, 10.0, 0) { Name = "0 Partitionen" };
            int idx1 = dim.GetPartitionNumber(-0.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "less lower bound in 0-Partitions should be RL.Tiling.OutOfBounds.");
            idx1 = dim.GetPartitionNumber(0.0);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "lower bound in 0-Partitions should be RL.Tiling.OutOfBounds.");
            idx1 = dim.GetPartitionNumber(10.0);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "upper bound in 0-Partitions should be RL.Tiling.OutOfBounds.");
            idx1 = dim.GetPartitionNumber(10.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "greater upper bound in 0-Partitions should be RL.Tiling.OutOfBounds.");
        }

        [TestMethod]
        public void CheckDimension_1Partitionen() {
            RL.Tiling dim = new RL.Tiling(0.0, 10.0, 1) { Name = "1 Partitionen" };
            int idx1 = dim.GetPartitionNumber(-0.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "less lower bound in 1-Partitions should be RL.Tiling.OutOfBounds.");
            idx1 = dim.GetPartitionNumber(0.0);
            Assert.AreEqual<int>(0, idx1, "lower bound in 1-Partitions should be 0");
            idx1 = dim.GetPartitionNumber(5.0);
            Assert.AreEqual<int>(0, idx1, "in-bound in 1-Partitions should be 0");
            idx1 = dim.GetPartitionNumber(10.0);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "upper bound in 1-Partitions should be RL.Tiling.OutOfBounds.");
            idx1 = dim.GetPartitionNumber(10.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "greater upper bound in 1-Partitions should be RL.Tiling.OutOfBounds.");
        }

        [TestMethod]
        public void CheckDimension_3Partitionen() {
            RL.Tiling dim = new RL.Tiling(0.5, 5.0, 3) { Name = "3 Partitionen" };
            int idx1 = dim.GetPartitionNumber(-0.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "less lower bound in 3-Partitions should be RL.Tiling.OutOfBounds.");

            idx1 = dim.GetPartitionNumber(0.5);
            Assert.AreEqual<int>(0, idx1, "lower bound in 3-Partitions should be 0");

            idx1 = dim.GetPartitionNumber(1.9);
            Assert.AreEqual<int>(0, idx1, "expexted Index was 0");

            idx1 = dim.GetPartitionNumber(2.0);
            Assert.AreEqual<int>(1, idx1, "expexted Index was 1");

            idx1 = dim.GetPartitionNumber(3.5);
            Assert.AreEqual<int>(2, idx1, "expexted Index was 2");

            idx1 = dim.GetPartitionNumber(5.0);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "upper bound in 3-Partitions should be RL.Tiling.OutOfBounds.");

            idx1 = dim.GetPartitionNumber(10.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "greater upper bound in 3-Partitions should be RL.Tiling.OutOfBounds.");
        }

        [TestMethod]
        public void CheckDimension_3PartitionenNegativ() {
            RL.Tiling dim = new RL.Tiling(-0.5, 4.0, 3) { Name = "3 Partitionen Negativ" };
            int idx1 = dim.GetPartitionNumber(-0.51);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "less lower bound in 3-Partitions should be RL.Tiling.OutOfBounds.");

            idx1 = dim.GetPartitionNumber(-0.5);
            Assert.AreEqual<int>(0, idx1, "lower bound in 3-Partitions should be 0");

            idx1 = dim.GetPartitionNumber(0.99);
            Assert.AreEqual<int>(0, idx1, "expexted Index was 0");

            idx1 = dim.GetPartitionNumber(1.0);
            Assert.AreEqual<int>(1, idx1, "expexted Index was 1");

            idx1 = dim.GetPartitionNumber(2.5);
            Assert.AreEqual<int>(2, idx1, "expexted Index was 2");

            idx1 = dim.GetPartitionNumber(4.0);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "upper bound in 3-Partitions should be RL.Tiling.OutOfBounds.");

            idx1 = dim.GetPartitionNumber(10.1);
            Assert.AreEqual<int>(RL.Tiling.OutOfBounds, idx1, "greater upper bound in 3-Partitions should be RL.Tiling.OutOfBounds.");
        }

        [TestMethod]
        public void CheckDimension_GetMedian() {
            RL.Tiling dim = new RL.Tiling(-0.5, 4.0, 3) { Name = "3 Partitionen Negativ" };
            // Partitionslänge = 1.5 / Mitte = 0.75
            double median = dim.GetMedian(0);
            Assert.AreEqual<double>(0.25, median, "Wrong Median for partition 0 of 2");
            median = dim.GetMedian(1);
            Assert.AreEqual<double>(1.75, median, "Wrong Median for partition 1 of 2");
            median = dim.GetMedian(2);
            Assert.AreEqual<double>(3.25, median, "Wrong Median for partition 2 of 2");
            median = dim.GetMedian(-1);
            Assert.AreEqual<double>(Double.NegativeInfinity, median, "Expected: Double.NegativeInfinity");
            median = dim.GetMedian(3);
            Assert.AreEqual<double>(Double.PositiveInfinity, median, "Expected: Double.PositiveInfinity");
        }

        [TestMethod]
        public void CheckDimension_GetMedian2() {
            RL.Tiling dim = new RL.Tiling(0.5, 5.0, 3) { Name = "3 Partitionen Negativ" };
            // Partitionslänge = 1.5 / Mitte = 0.75
            double median = dim.GetMedian(0);
            Assert.AreEqual<double>(1.25, median, "Wrong Median for partition 0 of 2");
            median = dim.GetMedian(1);
            Assert.AreEqual<double>(2.75, median, "Wrong Median for partition 1 of 2");
            median = dim.GetMedian(2);
            Assert.AreEqual<double>(4.25, median, "Wrong Median for partition 2 of 2");
            median = dim.GetMedian(-1);
            Assert.AreEqual<double>(Double.NegativeInfinity, median, "Expected: Double.NegativeInfinity");
            median = dim.GetMedian(3);
            Assert.AreEqual<double>(Double.PositiveInfinity, median, "Expected: Double.PositiveInfinity");
        }
    }
}
